package com.bawei.play.repos

import com.bawei.common.entity.CommendEntity
import com.bawei.common.entity.VideoEntity
import com.bawei.http.ApiBaseResponse
import com.bawei.play.api.PlayServerApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject


/**
 * Hilt会在当前包下寻找Hilt模块，并初始化构造函数中变量
 */
class PlayRepository @Inject constructor(private val apiServer: PlayServerApi) {


    suspend fun getRecommendVideo(page:Int, pageSize: Int): ApiBaseResponse<List<VideoEntity>>{
        return apiServer.getRecommendSimpleVideo(page, pageSize)
    }

    suspend fun getVideoByChannelId(channelId:String, page:Int, pageSize: Int): Flow<List<VideoEntity>> {
        return flow {
            var result = apiServer.getSimpleVideoByChannelId(channelId, page, pageSize)
            if(result.code == 0){
                emit(result.data) //发送数据
            }else{
                emit(listOf()) //发送空数据
            }
        }
    }

    suspend fun getVideoCommends(dataType: Int, itemId: String): ApiBaseResponse<List<CommendEntity>>{
        return apiServer.getVideoCommends(dataType, itemId)
    }

}